var express = require('express');
var router = express.Router();

var mysql      = require('mysql');
var pool  = mysql.createPool({
  connectionLimit : 50,
  host     : '119.23.26.58',
  user     : 'lzxy',
  password : '216857',
  database : 'support'
});


/* GET home page. */
router.get('/', function(req, res, next) {
  // connection.query('select * from shuiping01 order by time desc limit 20', function (error, results, fields) {
  //   console.log(results)
  // })
  let type = req.query.type
  res.render('index', { title: 'Express', type });
});
router.get('/api/db/physical', function(req, res, next) {
  let type = req.query.type

  pool.query('select * from ?? order by time desc limit 20', [type], function (error, results, fields) {
    // console.log(results)
    let data = []
    if(results) {
      results.map(item => {
        data.push({time: item.time, value: item.value})
      })
      res.json({data, errno: 0})
    } else {
      res.json({errno:1, msg:'数据表不存在'})
    }
  })
});
module.exports = router;
